﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Entity;
using MSD.WL.Site.Models;

namespace MSD.WL.Site.Controllers
{
    [Authorize]
    public class ProductionController : Controller
    {
        private EMSContext db = new EMSContext();

        #region 生产计划
        // GET: Production
        public ActionResult proPlan()
        {
            return View();
        }
        /// <summary>
        /// 获取生产计划记录
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult getproPlanRecords(int offset,int limit)
        {
            var proPlan = db.ProducePlan as IQueryable<ProducePlan>;
            var productionPlan = proPlan.Select(x => new { ID = x.ID, PlanCode = x.PlanCode, PlanDate = x.PlanDate, OperatorCode = x.OperatorCode, SEOrderCode = x.SEOrderCode, InvenCode = x.InvenCode, Quantity = x.Quantity, FinishDate = x.FinishDate, IsFlag = x.IsFlag }).ToList();
            var total = productionPlan.Count();
            var rows = productionPlan.OrderBy(x => x.ID).Skip(offset).Take(limit).ToList();
            return Json(new { total = total, rows = rows });
        }
        #endregion

        #region 生产入库
        // GET: Production
        public ActionResult proItem()
        {
            return View();
        }
        /// <summary>
        /// 获取生产入库记录
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult getproPutinRecords(int offset, int limit)
        {
            var proPutin = db.ProduceItem as IQueryable<ProduceItem>;
            var productionItem = proPutin.Select(x => new { ID = x.ID, ProduceCode = x.ProduceCode, InvenCode = x.InvenCode, Quantity = x.Quantity, GetQuantity = x.GetQuantity, UseQuantity = x.UseQuantity }).ToList();
            var total = productionItem.Count();
            var rows = productionItem.OrderBy(x => x.ID).Skip(offset).Take(limit).ToList();
            return Json(new { total = total, rows = rows });
        }
        #endregion

        #region 销售订单
        // GET: Production
        public ActionResult selOrder()
        {
            return View();
        }
        /// <summary>
        /// 获取销售订单记录
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult getselOrderRecords(int offset, int limit)
        {
            var selOrder = db.SEOrder as IQueryable<SEOrder>;
            var seOrder = selOrder.Select(x => new { ID = x.ID, SEOrderCode = x.SEOrderCode, SEOrderDate = x.SEOrderDate, OperatorCode = x.OperatorCode, CustomerCode = x.CustomerCode, StoreCode = x.StoreCode, InvenCode = x.InvenCode, SellPrice = x.SellPrice, Quantity = x.Quantity, SEMoney = x.SEMoney, SenInvenDate = x.SenInvenDate, EmployeeCode = x.EmployeeCode, IsFlag = x.IsFlag }).ToList();
            var total = seOrder.Count();
            var rows = seOrder.OrderBy(x => x.ID).Skip(offset).Take(limit).ToList();
            return Json(new { total = total, rows = rows });
        }
        #endregion

        #region 销售收款单
        // GET: Production
        public ActionResult selGather()
        {
            return View();
        }
        /// <summary>
        /// 获取销售收款单记录
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult getselGatherRecords(int offset, int limit)
        {
            var selGather = db.SEGather as IQueryable<SEGather>;
            var seGather = selGather.Select(x => new { ID = x.ID, SEGatherCode = x.SEGatherCode, SEGatherDate = x.SEGatherDate, OperatorCode = x.OperatorCode, CustomerCode = x.CustomerCode, SEMoney = x.SEMoney, AccountCode = x.AccountCode, EmployeeCode = x.EmployeeCode, Remark = x.Remark, IsFlag = x.IsFlag }).ToList();
            var total = seGather.Count();
            var rows = seGather.OrderBy(x => x.ID).Skip(offset).Take(limit).ToList();
            return Json(new { total = total, rows = rows });
        }
        #endregion
    }
}